﻿using Mengsk.ProxyDelivery.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mengsk.ProxyDelivery.Service
{
    public class NoteService : ServiceBase<Note>
    {

        private const string APIURL_CREATE = "/webservice/note/create.html";
        private const string APIURL_MARKSTATE = "/webservice/note/markstate.html";
        private const string APIURL_DELETE = "/webservice/note/delete.html";

        public DataCollection<Note> GetByAll(String op, int state, int pageIndex, int pageSize)
        {
            Request req = new Request { Api = "getByAll" };
            req.Add("operator", op);
            req.Add("state", state);
            req.Add("pageIndex", pageIndex);
            req.Add("pageSize", pageSize);
            return this.DoRemoteCall<Note>(req).ToDataCollection();
        }

        public int Create(long orderId, string goodsInfo, String comment, int type, int targetType, DateTime notifyTime)
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            para.Add("orderId", orderId.ToString());
            para.Add("goodsInfo", goodsInfo);
            para.Add("comment", comment);
            para.Add("type", type.ToString());
            para.Add("targetType", targetType.ToString());
            para.Add("notifyTime", this.FormatToDBTime(notifyTime).ToString("yyyy-MM-dd HH:mm:ss"));

            var ret = this.DoPost<int>(APIURL_CREATE, para);
            if (ret == null || ret.Datas.Count < 1)
            {
                throw new Exception("服务端没有返回值");
            }

            return ret.Datas[0];
        }

        public void MarkState(int id, NoteState state)
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            para.Add("id", id.ToString());
            para.Add("state", ((int)(state)).ToString());
            this.DoPost<int>(APIURL_MARKSTATE, para);
        }

        public void Delete(int id)
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            para.Add("id", id.ToString());
            this.DoPost<int>(APIURL_DELETE, para);
        }
    }
}
